<?php

include_once '../AtacCommunicator/ACRoutePlanner.php';
include_once '../AtacCommunicator/ACBusWaitingTimes.php';
include_once '../Exceptions/CommunicationException.php';
include_once '../InfoManager/InfoManager.php';
include_once '../Model/BusStop.php';
include_once '../Model/Location.php';
include_once '../Model/Address.php';
include_once '../Model/GPS.php';


if ((isset($_GET["lat"])) && (isset($_GET["long"])))
{
	$lat = floatval(RMobUtils::escape_var($_GET["lat"]));
	$long = floatval(RMobUtils::escape_var($_GET["long"]));
	$test = new GPS($lat,$long);
}
else if (isset($_GET["start"]))
{
	$start = new Location(RMobUtils::escape_var($_GET["start"],null,null));
	$test=$start->getGPS();		
}
else return;
	
	$im = new InfoManager();
	if (isset($_GET["distance"])) $meters=intval(RMobUtils::escape_var($_GET["distance"]));
	else if ($_GET["service"]=='ARView') $meters=700;
	else $meters=700;	
	
	$stops = $im->getStopsCloserThan($meters,$test);
	
	$xml = "";
	
	if ($stops != NULL)
	{
		try {
			foreach ($stops as $stop)
			{
		
					//Compact mode 
					$xml .= $stop->toXML(COMPACT_MODE);
			}
		}
		catch (CommunicationException $e)
		{
			echo $e->toXML(EXTENDED_MODE);
			exit(1);
		}
	}

	$xml = "<STOPSAROUND>".$xml."</STOPSAROUND>";
	echo $xml;


?>